<?php

require_once 'plugin/DBPlugin.php';

/**
 * Manejo de los planes de vivienda.
 */
class PlanesDBPlugin extends DBPlugin {

	

	/**
	 * Obtener todos planes de vivienda
	 */	
	public static function getPlanesPublished() {

		require_once ('include/connect.php');
		
		$sql = "SELECT * FROM `planes`";
		$sql .= " WHERE published = 1";
		$results = mysql_query($sql);
	
		$planes = array();
		while($plan = mysql_fetch_assoc($results)) {
			$planes[] = $plan;
		}
		
		return $planes;
		
	}
	
	
	
	/**
	 * Obtener un plan por id
	 */	
	public static function getById($id) {

		require_once ('include/connect.php');
		
		$sql = "SELECT * FROM `planes` where idplan = ".$id;
		$result = mysql_query($sql);
		$num = mysql_num_rows($result);
		if ($num > 0) {
			$row = mysql_fetch_array($result);
			return $row;
		}
		return null;
	
	}
	
	
	/**
	 * Obtiene las imagenes de un plan
	 */
	public static function getImages($idPlan, $imagetype) {

		require_once ('include/connect.php');
	
		$sql = "select * from `images`".
		 		" where tablename = 'planes'".
				" and iditem = ".$idPlan.
				" and imagetype = '".$imagetype."'";
		$results = mysql_query($sql);

		$fotos = array();
		while($foto = mysql_fetch_assoc($results)) {
			$fotos[] = $foto;
		}
		
		return $fotos;
	}
}

?>